package com.hskn.hss.module.statistics.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hskn.hss.entity.AjaxResult;
import com.hskn.hss.exception.HssException;
import com.hskn.hss.module.tlcar.service.ITlCarService;
import com.hskn.hss.module.tlrepaircfg.service.ITlRepairCfgService;
import com.hskn.hss.utils.Tools;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 车辆维护情况
 *
 * @author hskn
 * @since 2021-05-25
 */
@Slf4j
@RestController
@RequestMapping("/hss/vehiclemaintenance")
public class VehicleMaintenanceController {

    @Autowired
    private ITlRepairCfgService tlRepairCfgService;

    @Autowired
    ITlCarService tlCarService;

    /**
     * 机构维修统计-运行情况
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "getJgwxtjYxqk", method = RequestMethod.POST)
    public AjaxResult<Object> getJgwxtjYxqk(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            JSONObject json = new JSONObject();

            int cls = tlCarService.getCls(params);
            json.put(" cls", cls);
            int ljwxcs = tlRepairCfgService.getLjwxcs(params);
            json.put("ljwxcs", ljwxcs);
            int ljwxfy = tlRepairCfgService.getLjwxfy(params);
            json.put("ljwxfy", ljwxfy);
            float ljlc = tlRepairCfgService.getLjlc(params);
            json.put("ljlc", ljlc);
            int dcpjwxcs = tlRepairCfgService.getDcpjwxcs(params);
            json.put("dcpjwxcs", dcpjwxcs);
            int dcpjwxlcjg = tlRepairCfgService.getDcpjwxlcjg(params);
            json.put("dcpjwxlcjg", dcpjwxlcjg);
            int dcpjwxsjjg = tlRepairCfgService.getDcpjwsjjg(params);
            json.put("dcpjwxsjjg", dcpjwxsjjg);
            return AjaxResult.success(json);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    /**
     * 机构维修统计-总维修统计-图表
     *
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "getJgwxtjZwxtjChart", method = RequestMethod.POST)
    public AjaxResult<Object> getJgwxtjZwxtjChart(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            JSONObject json = tlRepairCfgService.getJgwxtjZwxtjChart(params);
            return AjaxResult.success(json);
        } catch (HssException e) {
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    /**
     * 机构维修统计-机构维修次数排名-平均车辆-图表
     *
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "getJgwxtjJgwxcspmPjclChart", method = RequestMethod.POST)
    public AjaxResult<Object> getJgwxtjJgwxcspmPjclChart(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            JSONObject json = tlRepairCfgService.getJgwxtjJgwxcspmPjclChart(params);
            return AjaxResult.success(json);
        } catch (HssException e) {
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    /**
     * 机构维修统计-机构维修次数排名-维修总数-图表
     *
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "getJgwxtjJgwxcspmWxzsChart", method = RequestMethod.POST)
    public AjaxResult<Object> getJgwxtjJgwxcspmWxzsChart(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            JSONObject json = tlRepairCfgService.getJgwxtjJgwxcspmWxzsChart(params);
            return AjaxResult.success(json);
        } catch (HssException e) {
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    /**
     * 机构维修统计-机构维修费用排名-平均车辆-图表
     *
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "getJgwxtjJgwxfypmPjclChart", method = RequestMethod.POST)
    public AjaxResult<Object> getJgwxtjJgwxfypmPjclChart(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            JSONObject json = tlRepairCfgService.getJgwxtjJgwxfypmPjclChart(params);
            return AjaxResult.success(json);
        } catch (HssException e) {
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    /**
     * 机构维修统计-机构维修费用排名-维修总数-图表
     *
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "getJgwxtjJgwxfypmWxzsChart", method = RequestMethod.POST)
    public AjaxResult<Object> getJgwxtjJgwxfypmWxzsChart(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            JSONObject json = tlRepairCfgService.getJgwxtjJgwxfypmWxzsChart(params);
            return AjaxResult.success(json);
        } catch (HssException e) {
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    /**
     * 机构维修统计-车辆维修分布-作业大类分布-次数-图表
     *
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "getJgwxtjClwxfbZydlfbCsChart", method = RequestMethod.POST)
    public AjaxResult<Object> getJgwxtjClwxfbZydlfbCsChart(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            JSONObject json = tlRepairCfgService.getJgwxtjClwxfbZydlfbCsChart(params);
            return AjaxResult.success(json);
        } catch (HssException e) {
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    /**
     * 机构维修统计-车辆维修分布-车辆类型分布-次数-图表
     *
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "getJgwxtjClwxfbCllxfbCsChart", method = RequestMethod.POST)
    public AjaxResult<Object> getJgwxtjClwxfbCllxfbCsChart(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            JSONObject json = tlRepairCfgService.getJgwxtjClwxfbCllxfbCsChart(params);
            return AjaxResult.success(json);
        } catch (HssException e) {
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    /**
     * 机构维修统计-车辆维修分布-车龄分布-次数-图表
     *
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "getJgwxtjClwxfbClfbCsChart", method = RequestMethod.POST)
    public AjaxResult<Object> getJgwxtjClwxfbClfbCsChart(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            JSONObject json = tlRepairCfgService.getJgwxtjClwxfbClfbCsChart(params);
            return AjaxResult.success(json);
        } catch (HssException e) {
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    /**
     * 机构维修统计-车辆维修分布-作业大类分布-费用-图表
     *
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "getJgwxtjClwxfbZydlfbFyChart", method = RequestMethod.POST)
    public AjaxResult<Object> getJgwxtjClwxfbZydlfbFyChart(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            JSONObject json = tlRepairCfgService.getJgwxtjClwxfbZydlfbFyChart(params);
            return AjaxResult.success(json);
        } catch (HssException e) {
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    /**
     * 机构维修统计-车辆维修分布-车辆类型分布-费用-图表
     *
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "getJgwxtjClwxfbCllxfbFyChart", method = RequestMethod.POST)
    public AjaxResult<Object> getJgwxtjClwxfbCllxfbFyChart(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            JSONObject json = tlRepairCfgService.getJgwxtjClwxfbCllxfbFyChart(params);
            return AjaxResult.success(json);
        } catch (HssException e) {
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    /**
     * 机构维修统计-车辆维修分布-车龄分布-费用-图表
     *
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "getJgwxtjClwxfbClfbFyChart", method = RequestMethod.POST)
    public AjaxResult<Object> getJgwxtjClwxfbClfbFyChart(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            JSONObject json = tlRepairCfgService.getJgwxtjClwxfbClfbFyChart(params);
            return AjaxResult.success(json);
        } catch (HssException e) {
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }
}
